{% extends 'TopxiaWebBundle:Group:layout.html.twig' %}
{% set script_controller = 'group/group' %}
{% block title %}{{threadMain.title}} - {{ groupinfo.title }} {{ parent() }}{% endblock %}
{% block keywords %}{{groupinfo.title}}{% endblock %}
{% block description %}{{threadMainContent|plain_text(100)}}{% endblock %}

{% block group_main %}
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">
        {{ threadMain.title }}
        {% if threadMain.isStick %}
          <span class="label label-primary">{{'置顶'|trans}}</span>
        {% endif %}
        {% if threadMain.isElite %}
          <span class="label label-danger">{{'精华'|trans}}</span>
        {% endif %}
        {% if is_feature_enabled('group_reward') %}
          {% if threadMain.type == 'reward' and threadMain.rewardCoin > 0 %}
            <span class="label label-danger">{{'奖'|trans}}</span>
            <span style="color:#d9534f;" class="mll"> {{'悬赏'|trans}}:{{threadMain.rewardCoin}}{{setting('coin').coin_name}}</span>
          {% endif %}
        {% endif %}
      </h3>
    </div>
    <div class="panel-body clearfix" id="post-action">
      <div class="well well-sm text-sm color-gray clearfix" style="line-height:20px">
        <div class="es-share dropdown pull-right">
          <span class="es-share top" style="font-size:14px;">
            <a href="javascript:;" class="gray-dark" data-toggle="dropdown"><i class="es-icon es-icon-share"></i> {{'分享'|trans}}</a>
            {% include 'TopxiaWebBundle:Common:share-dropdown.html.twig' with {type:'group_thread', thread:threadMain, group:groupinfo} %}
          </span>
        </div>
        <div class="pull-right mrm" id="thread-list">
          {% if threadMain.userId != user.id %}
            <a href="javascript:;" class="uncollect-btn link-dark" data-url="{{ path('group_thread_uncollect', {threadId:threadMain.id}) }}" {% if isCollected == false %} style="display:none;"{% endif %}><i class="es-icon es-icon-favorite mrs"></i> {{'已收藏'|trans}}</a>
            <a href="javascript:;" class="collect-btn link-dark" data-url="{{ path('group_thread_collect', {threadId:threadMain.id}) }}" {% if isCollected == true %} style="display:none;"{% endif %}><i class="es-icon es-icon-favoriteoutline mrs"></i>{{'收藏'|trans}}</a>
          {% endif %}
        </div>
        {{'发表于'|trans}} {{ threadMain.createdTime|smart_time }}
        <span class="mll">{{ threadMain.hitNum }} {{'次查看'|trans}}</span>
      </div>

      {{threadMain.content|raw}}
      {% if attachs %}
        <hr>
        <span class="glyphicon glyphicon-paperclip"></span> {{'附件下载'|trans}} :
        <div class="row clearfix mtm">
          {% for attach in attachs %}
            <div class="pull-left attach col-md-4 col-sm-6 col-lg-4"  data-toggle="tooltip" data-placement="top" title="{% if  attach.description %}描述：{{attach.description}}{% endif %}  上传于 {{files[attach.fileId].createdTime|smart_time}}">
              {% if attach.coin > 0  and   user.id != attach.userId and app.user %}
                <a href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_buy_attach',{attachId:attach.id})}}" class="pull-left mrm"><img src="{{ default_path(attach.title|file_type(".png")) }}" class="avatar-md"></a>
              {% else %}
                <a href="{{path('group_attach_download',{fileId:attach.id})}}" class="pull-left mrm"><img src="{{ default_path(attach.title|file_type(".png")) }}" class="avatar-md"></a>
              {% endif %}
              <div class="media-body">
                <div class="metas mts">
                  {% if attach.coin > 0 and  user.id != attach.userId and app.user %}
                    <strong><a href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_buy_attach',{attachId:attach.id})}}">{{ attach.title }}</a></strong>
                  {% else %}
                    <strong><a href="{{path('group_attach_download',{fileId:attach.id})}}">{{ attach.title }}</a></strong>
                  {% endif %}
                </div>

                <div class="content" style="color: #999;font-size:11px;">
                  {{files[attach.fileId].size|file_size}}
                  {% if attach.coin > 0 %}
                    <span class="mls">{{'售价'|trans}}:{{attach.coin}}{{setting('coin').coin_name}}</span>
                    {% else %}
                    <span class="mls">{{'免费'|trans}}</span>
                  {% endif %}
                  <br>{{'下载次数：'|trans}}{{attach.hitNum}}
                </div>
              </div>
            </div>
          {% endfor %}
        </div>
      {% endif %}
      <div class="mtl text-right">
        {% if is_feature_enabled('group_reward') and threadMain.count == 1 %}
          {% if user.id==owner.id or is_granted('ROLE_ADMIN') or user.id==groupinfo.ownerId or is_groupmember==3 %}
          {% else %}
            {% if app.user %}
            <a class="btn btn-default btn-sm mrm" href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_hide',{threadId:threadMain.id})}}">{{'查看隐藏内容'|trans}}</a>
            {% endif %}
          {% endif %}
        {% endif %}

        {% if user.id==owner.id or is_granted('ROLE_ADMIN') or user.id==groupinfo.ownerId or is_groupmember==3 %}
          <a class="btn btn-default btn-sm mrm" href="{{path('group_thread_update',{id:groupinfo.id,threadId:threadMain.id})}}"> {{'编辑'|trans}}</a>
        {% endif %}

        {% if is_groupmember==2 or is_granted('ROLE_ADMIN') or is_groupmember==3 %}
          {% if threadMain.isElite==1 %}
            <a id="elite"  title="{{'取消加精'|trans}}" class="btn btn-default btn-sm mrm"
              href="javascript:"
            data-url="{{path('group_thread_removeElite',{threadId:threadMain.id})}}">{{'取消加精'|trans}}</a>
          {% else %}
            <a id="elite"  title="{{'加精'|trans}}" class="btn btn-default btn-sm mrm"
            href="javascript:" data-url="{{path('group_thread_setElite',{threadId:threadMain.id})}}">{{'加精'|trans}}</a>
          {% endif %}

          {% if threadMain.isStick==1 %}
             <a id="stick" title="{{'取消置顶'|trans}}" class="btn btn-default btn-sm mrm"
            href="javascript:" data-url="{{path('group_thread_removeStick',{threadId:threadMain.id})}}"> {{'取消置顶'|trans}}</a>
          {% else %}
            <a id="stick"  title="{{'置顶'|trans}}" class="btn btn-default btn-sm mrm"
            href="javascript:" data-url="{{path('group_thread_setStick',{threadId:threadMain.id})}}">{{'置顶'|trans}}</a>
          {% endif %}

          {% if is_feature_enabled('group_reward') %}
            {% if is_granted('ROLE_ADMIN') or user.id==groupinfo.ownerId or is_groupmember==3 %}
              {% if threadMain.type == 'reward' and  threadMain.rewardCoin > 0 %}
                {% if not isAdopt %}
                  <a id="cancelReward" title="{{'取消悬赏'|trans}}" class="btn btn-default btn-sm mrm"
                  href="javascript:" data-url="{{path('group_thread_cancel_reward',{threadId:threadMain.id})}}"><span class="glyphicon glyphicon-ban-circle"></span> {{'取消悬赏'|trans}}</a>
                {% endif %}
              {% else %}
                {% if threadMain.type == 'default' %}
                  <a id="rewardCoin"  title="{{'悬赏'|trans}}" class="btn btn-default btn-sm mrm"
                    href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_reward',{threadId:threadMain.id})}}"><span class="glyphicon glyphicon-usd"></span>  {{'悬赏'|trans}}</a>
                {% endif %}
              {% endif %}
            {% endif %}
          {% endif %}
        {% endif %}
        {% if filters.type=='onlyOwner' %}
          <a class="btn btn-default btn-sm mrm" href="{{path('group_thread_show',{id:groupinfo.id,threadId:threadMain.id,type:'all',sort:filters.sort})}}" %}><span class="glyphicon glyphicon-filter"></span> {{'查看全部'|trans}}</a>
        {% else %}
          <a class="btn btn-default btn-sm mrm" href="{{path('group_thread_show',{id:groupinfo.id,threadId:threadMain.id,type:'onlyOwner',sort:filters.sort})}}">{{'只看楼主'|trans}}</a>
        {% endif %}

        {% if filters.sort=='desc' %}
          <a type="button" class="btn btn-default btn-sm mrm" href="{{path('group_thread_show',{id:groupinfo.id,threadId:threadMain.id,type:filters.type,sort:'asc'})}}">{{'顺序查看'|trans}}</a>
        {% else %}
          <a type="button" class="btn btn-default btn-sm mrm" href="{{path('group_thread_show',{id:groupinfo.id,threadId:threadMain.id,type:filters.type,sort:'desc'})}}">{{'倒序查看'|trans}}</a>
        {% endif %}
      </div>
    </div>
  </div>

  {% if is_feature_enabled('group_reward') %}
    {% if isAdopt %}
    <div class="panel panel-default group-post-list">
      <div class="panel-heading" style="color:#d9534f;">
        {{'最佳回答'|trans}}
      </div>
      <div class="panel-body">
        <ul class="media-list">
          <li class="media">
            <a href="{{ path('user_show', {id:isAdopt[0].userId}) }}" class="pull-left"><img src="{{ filepath(postMember[isAdopt[0].userId].smallAvatar, 'avatar.png') }}" class="avatar-md"></a>
            <div class="media-body">
              <div class="metas">
                <strong>{{ web_macro.user_link(postMember[isAdopt[0].userId]) }}</strong>
                <span class="mhm">{{isAdopt[0].createdTime|smart_time}} </span>
              </div>
              <div class="content">
                {{isAdopt[0].content|raw}}
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
    {% endif %}
  {% endif %}

  {% if threadMain.postNum %}
  <div class="panel panel-default group-post-list">
    <div class="panel-heading">
      {{threadMain.postNum}}{{'回复'|trans}}
    </div>
    <div class="panel-body">
      <ul class="media-list">
        {% for post in post %}
          {% set subPosts = postReply[post.id]|default(null) %}
          <li id="post-{{post.id}}" class="media">
            <a href="{{ path('user_show', {id:post.userId}) }}" class="pull-left"><img src="{{ filepath(postMember[post.userId].smallAvatar, 'avatar.png') }}" class="avatar-sm"></a>
            <div class="media-body">
              <div class="metas">
                <span class="floor">
                  {% if filters.sort=='desc' %}
                    {{ (postCount+1)-paginator.getPerPageCount()*(paginator.currentPage-1)-loop.index0 }}{{'楼'|trans}}
                  {% else %}
                    {{ (loop.index+1)+paginator.getPerPageCount()*(paginator.currentPage-1) }}{{'楼'|trans}}
                  {% endif %}
                </span>
                <strong>{{ web_macro.user_link(postMember[post.userId]) }}</strong>
                <span class="divider mhm">•</span>
                <span >{{post.createdTime|smart_time}} </span>
              </div>

              <div class="content editor-text">
                {{post.content|raw}}
              </div>

              <div class="actions">
                {% if user.id==post.userId or is_granted('ROLE_ADMIN')  or is_groupmember==3  or is_groupmember==2 %}
                  <a title="{{'确定删除这条回复'|trans}}" class="mhm post-delete-btn" href="javascript:" data-url="{{path('group_thread_deletePost',{postId:post.id})}}">{{'删除'|trans}}</a>
                {% endif %}

                {% if is_feature_enabled('group_reward') %}
                  {% if not isAdopt and threadMain.type == "reward" %}
                    {% if is_granted('ROLE_ADMIN')  or is_groupmember==3  or is_groupmember==2 %}
                      <a title="{{'确定采纳这条回复'|trans}}" class="mhm post-adopt-btn" href="javascript:" data-url="{{path('group_thread_adopt',{postId:post.id})}}">{{'采纳'|trans}}</a>
                    {% endif %}
                  {% endif %}
                {% endif %}

                {% if not subPosts %}
                  <a href="javascript:" class="reply" id="reply-{{post.id}}"  postId="{{post.id}}" postName="{{postMember[post.userId].nickname}}" data-from-user-id-nosub="{{postMember[post.userId].id}}">{{'回复'|trans}}</a>
                  <a href="javascript:" class="unreply" id="unreply-{{post.id}}" postId="{{post.id}}" style="display:none;">{{'收起'|trans}}</a>
                {% else %}
                  <a style="display:none;" href="javascript:" class="reply" id="reply-{{post.id}}"  postId="{{post.id}}" postName="{{postMember[post.userId].nickname}}" data-from-user-id-nosub="">{{'回复'|trans}}({{postReplyCount[post.id]}})</a>
                  <a href="javascript:" class="unreply" id="unreply-{{post.id}}" postId="{{post.id}}" >{{'收起'|trans}}</a>
                {% endif %}
              </div>
              <div class="reply-{{post.id}}">
                {% if subPosts %}
                  {% include 'TopxiaWebBundle:Group:post-reply-list.html.twig' with {posts:subPosts, users:postReplyMembers,postMain:post} %}
                {% else %}
                  <div class="reply-{{post.id}}" style="display:none;">
                    <form  class="thread-post-reply-form reply-{{post.id}}" method="post"  post-url="{{path('group_thread_post',{groupId:groupinfo.id,threadId:threadMain.id})}}">
                      <div class="form-group">
                        <label class="control-label hide" for="reply-content-{{post.id}}">{{'回复内容'|trans}}</label>
                        <div class="controls">
                        <textarea id="reply-content-{{post.id}}" class="form-control" data-image-upload-url="{{ path('editor_upload', {token:upload_token('default')}) }}"></textarea>
                      </div>
                      </div>
                      <div id="fromUserIdNoSubDiv"></div>
                      <div class="form-group">
                        <button type="submit" postId="{{post.id}}" class="reply-btn btn btn-xs btn-primary pull-right" style="margin-top:-10px;"data-submiting-text="{{'正在发表回复'|trans}}">{{'发表'|trans}}</button>
                      </div>
                    </form>
                  </div>
                {% endif %}
              </div>
            </div>
          {% if postAttachs[post.id] %}
            <hr>
            <span class="glyphicon glyphicon-paperclip"></span> {{'附件下载'|trans}} :
            <div class="row clearfix mtm">
              {% for attach in postAttachs[post.id] %}
                {% set postFile = postFiles[post.id] %}
                <div class="pull-left attach col-md-4 col-sm-6 col-lg-4"  data-toggle="tooltip" data-placement="top" title="{% if  attach.description %}{{'描述：'|trans}}{{attach.description}}{% endif %}  {{'上传于'|trans}} {{postFile[attach.fileId].createdTime|smart_time}}">
                  {% if attach.coin > 0  and app.user and  user.id != attach.userId %}
                    <a href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_buy_attach',{attachId:attach.id})}}" class="pull-left mrm"><img src="{{ default_path(attach.title|file_type(".png")) }}" class="avatar-md"></a>
                  {% else %}
                    <a href="{{path('group_attach_download',{fileId:attach.id})}}" class="pull-left mrm"><img src="{{ default_path(attach.title|file_type(".png")) }}" class="avatar-md"></a>
                  {% endif %}
                  <div class="media-body">
                    <div class="metas mts">
                      {% if attach.coin > 0 and  user.id != attach.userId and app.user %}
                        <strong><a href="javascript:" data-toggle="modal" data-target="#modal" data-urL="{{path('group_thread_buy_attach',{attachId:attach.id})}}">{{ attach.title }}</a></strong>
                      {% else %}
                        <strong><a href="{{path('group_attach_download',{fileId:attach.id})}}">{{ attach.title }}</a></strong>
                      {% endif %}
                    </div>
                    <div class="content" style="color: #999;font-size:11px;">
                      {{postFile[attach.fileId].size|file_size}}
                      {% if attach.coin > 0 %}
                        <span class="mls">{{'售价'|trans}}:{{attach.coin}}{{setting('coin').coin_name}}</span>
                        {% else %}
                        <span class="mls">{{'免费'|trans}}</span>
                      {% endif %}
                      <br>{{'下载次数：'|trans}}{{attach.hitNum}}
                    </div>
                    {% if user.id==post.userId or is_granted('ROLE_ADMIN')  or is_groupmember==3  or is_groupmember==2 %}
                      <a title="{{'确定删除此附件'|trans}}" class="mhm post-delete-btn" href="javascript:" data-url="{{path('group_thread_delete_attach',{goodsId:attach.id})}}">{{'删除'|trans}}</a>
                    {% endif %}
                  </div>
                </div>
              {% endfor %}
            </div>
          {% endif %}
          </li>
        {% endfor %}
      </ul>

      {{ web_macro.paginator(paginator) }}
    </div>
  </div>
  {% endif %}

  <div class="panel panel-default">
    <div class="panel-heading">{{'发表回复'|trans}}</div>
    <div class="panel-body">

      {% if app.user %}
        <form id="post-thread-form" class="post-thread-form thread-form" method="post" post-url="{{path('group_thread_post',{groupId:groupinfo.id,threadId:threadMain.id})}}">

          <div class="form-group">
            <label class="control-label hide" for="post_content">{{'回复内容'|trans}}</label>
            <div class="controls">
              <textarea name="content" value="" rows="10" id="post_content" class="form-control" data-image-upload-url="{{ path('editor_upload', {token:upload_token('default')}) }}" data-image-download-url="{{ path('editor_download', {token:upload_token('default')}) }}"></textarea>
            </div>
          </div>
          <div class="form-group">
            <div class="controls">
            <button id="post-thread-btn" data-submiting-text="{{'正在回复'|trans}}" type="submit" class="post-thread-btn btn btn-primary pull-right">{{'发表'|trans}}</button>
            </div>
          </div>
           {% if is_feature_enabled('group_reward') %}
            <input type="hidden" name="group_reward" id="group_reward">
           {% endif %}
          <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
        </form>
      {% else %}
        <div class="empty">
          你还没有登录，请先<a href="{{ path('login', {goto:app.request.server.get('REQUEST_URI')}) }}">登录</a>或<a href="{{ path('register', {goto:app.request.server.get('REQUEST_URI')}) }}">注册</a>！
        </div>
      {% endif %}
    </div>
  </div>
  {% include 'TopxiaWebBundle:Group:upload-modal.html.twig' %}
{% endblock %}

{% block group_side %}
  <div class="panel panel-default">
    <div class="panel-heading">{{'话题作者'|trans}}</div>
    <div class="panel-body">
      <div class="media">
        <div class="media-left prm">
          <a class="" href="{{ path('user_show', {id:owner.id}) }}">
            <img src="{{ filepath(owner.smallAvatar, 'avatar.png') }}" class="avatar-md">
          </a>
        </div>
        <div class="media-body ptm">
          <div>
            <a class="gray-darker">{{ web_macro.user_link(owner)}}</a>
          </div>
          <span class="text-sm gray-medium">{{owner.title|default("无"|trans)}}</span>
        </div>
      </div>
    </div>
  </div>

  {% if activeMembers %}
    {% include 'TopxiaWebBundle:Group:active-member-list.html.twig' with {activeMembers:activeMembers} %}
  {% endif %}

  <div class="panel panel-default">
    <div class="panel-heading">{{'热门小组'|trans}}</div>
    <div class="panel-body">
      {% set hotGroups = data('HotGroup',{'count':3}) %}
      {% for group in hotGroups %}
        <div class="media media-group">
          <div class="media-left">
            <a href="{{path('group_show',{id:group.id})}}" title="{{group.title}}">
              <img src="{{filepath(group.logo, 'group.png')}}" alt="{{group.title}}" class="avatar-square-md">
            </a>
          </div>
          <div class="media-body">
            <div class="title">
              <a class="gray-darker" href="{{ path('group_show',{id:group.id}) }}" title="{{group.title}}">
                {{group.title}}
              </a>
            </div>
            <div class="metas">
              <span><i class="es-icon es-icon-people"></i>{{group.memberNum}}</span>
              <span><i class="es-icon es-icon-textsms"></i>{{group.threadNum}}</span>
            </div>
          </div>
        </div>
      {% else %}
        <div class="empty">{{'暂无小组信息！'|trans}}</div>
      {% endfor %}
    </div>
  </div>

{% endblock %}
